home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 8.4 KB | 317 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: ShpTrakr.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef SHPTRAKR_H
- #include "ShpTrakr.h"
- #endif
-
- #ifndef UTILS_H
- #include "Utils.h"
- #endif
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef LINESHP_H
- #include "LineShp.h"
- #endif
-
- #ifndef OVALSHP_H
- #include "OvalShp.h"
- #endif
-
- #ifndef RECTSHP_H
- #include "RectShp.h"
- #endif
-
- #ifndef RRECTSHP_H
- #include "RRectShp.h"
- #endif
-
- #ifndef TEXTSHP_H
- #include "TextShp.h"
- #endif
-
- #ifndef DRAWVIEW_H
- #include "DrawView.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWSCROLR_H
- #include "FWScrolr.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWVIEW_H
- #include "FWView.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdraw
- #endif
-
- //========================================================================================
- // class CShapeTracker
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CShapeTracker::CShapeTracker
- //----------------------------------------------------------------------------------------
-
- CShapeTracker::CShapeTracker(Environment* ev, FW_CView* view, ODFacet* facet, CBaseShape* theShape, FW_Boolean gridOn) :
- FW_CTracker(ev, view, facet),
- fShape(theShape),
- fErase(FALSE),
- fGridOn(gridOn),
- fScroller(view->GetFrame(ev)->GetScroller(ev))
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CShapeTracker::~CShapeTracker
- //----------------------------------------------------------------------------------------
-
- CShapeTracker::~CShapeTracker()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CShapeTracker::BeginTracking
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CShapeTracker::BeginTracking(Environment* ev,
- const FW_CPoint& anchorPoint)
- {
- FW_CPoint point(anchorPoint);
- ForceToGrid(ev, point);
-
- fScroller->InitializeAutoScroll(ev);
-
- return point;
- }
-
- //----------------------------------------------------------------------------------------
- // CShapeTracker::ContinueTracking
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CShapeTracker::ContinueTracking(Environment* ev,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& previousPoint,
- const FW_CPoint& currentPoint)
- {
- FW_CPoint curLoc(currentPoint);
-
- ForceToGrid(ev, curLoc);
-
- if (previousPoint != curLoc)
- {
- FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
-
- if (fErase)
- fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, previousPoint, TRUE);
-
- fScroller->AutoScroll(ev, currentPoint, &vc);
-
- fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, curLoc, FALSE);
-
- fErase = TRUE;
- }
-
- return curLoc;
- }
-
- //----------------------------------------------------------------------------------------
- // CShapeTracker::EndTracking
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CShapeTracker::EndTracking(Environment* ev,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& lastPoint)
- {
- if (fErase)
- {
- FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
-
- fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, lastPoint, TRUE);
- }
-
- return anchorPoint != lastPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // CShapeTracker::ForceToGrid
- //----------------------------------------------------------------------------------------
-
- void CShapeTracker::ForceToGrid(Environment* ev, FW_CPoint& point)
- {
- if (fGridOn)
- {
- point.x = FW_IntToFixed((FW_FixedToInt(point.x) + 5) / 8 * 8);
- point.y = FW_IntToFixed((FW_FixedToInt(point.y) + 5) / 8 * 8);
- }
- }
-
- //========================================================================================
- // class CResizeTracker
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CResizeTracker::CResizeTracker
- //----------------------------------------------------------------------------------------
-
- CResizeTracker::CResizeTracker(Environment* ev,
- FW_CView* view, ODFacet* facet,
- CBaseShape* theShape, short whichHandle,
- const FW_CInk& resizeInk, const FW_CStyle& resizeStyle,
- FW_Boolean gridOn) :
- FW_CTracker(ev, view, facet),
- fShape(theShape),
- fWhichHandle(whichHandle),
- fResizeInk(resizeInk),
- fResizeStyle(resizeStyle),
- fErase(FALSE),
- fGridOn(gridOn),
- fScroller(view->GetFrame(ev)->GetScroller(ev))
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CResizeTracker::~CResizeTracker
- //----------------------------------------------------------------------------------------
-
- CResizeTracker::~CResizeTracker()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CResizeTracker::BeginTracking
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CResizeTracker::BeginTracking(Environment* ev, const FW_CPoint& anchorPoint)
- {
- FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
-
- FW_CPoint handleSize = vc.DeviceToLogical(2, 2);
-
- FW_CRectShape handle(FW_kZeroRect, FW_kFill);
- handle.SetInk(FW_kInvertInk);
- fShape->CalcHandle(fWhichHandle, &handle, handleSize);
- handle.Render(vc); // redraw the handle
-
- FW_CPoint point(anchorPoint);
- ForceToGrid(ev, point);
-
- FW_CPoint handleCenter;
- fShape->GetHandleCenter(fWhichHandle, handleCenter);
- fDelta = point - handleCenter;
-
- fScroller->InitializeAutoScroll(ev);
-
- return handleCenter;
- }
-
- //----------------------------------------------------------------------------------------
- // CResizeTracker::ContinueTracking
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CResizeTracker::ContinueTracking(Environment* ev,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& previousPoint,
- const FW_CPoint& currentPoint)
- {
- FW_UNUSED(anchorPoint);
-
- // ----- Adjust for the size of the handle
- FW_CPoint curLoc(currentPoint - fDelta);
- ForceToGrid(ev, curLoc);
-
- if (previousPoint != curLoc)
- {
- FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
-
- if (fErase)
- fShape->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, previousPoint); // erase
-
- fScroller->AutoScroll(ev, currentPoint, &vc);
-
- fShape->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, curLoc); // draw
-
- fErase = TRUE;
- }
-
- return curLoc;
- }
-
- //----------------------------------------------------------------------------------------
- // CResizeTracker::EndTracking
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CResizeTracker::EndTracking(Environment* ev,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& lastPoint)
- {
- FW_UNUSED(anchorPoint);
-
- fLastLocation = lastPoint - fDelta;
- ForceToGrid(ev, fLastLocation);
-
- if (fErase)
- {
- FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
-
- fShape->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, fLastLocation);
- }
-
- return anchorPoint != lastPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // CResizeTracker::ForceToGrid
- //----------------------------------------------------------------------------------------
-
- void CResizeTracker::ForceToGrid(Environment* ev, FW_CPoint& point)
- {
- if (fGridOn)
- {
- point.x = FW_IntToFixed((FW_FixedToInt(point.x) + 5) / 8 * 8);
- point.y = FW_IntToFixed((FW_FixedToInt(point.y) + 5) / 8 * 8);
- }
- }
-